﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IO;
namespace EDTS.Utils
{
    public class Serialize
    {
        /// <summary>
        /// 将一个xml文档反序列化为 类实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static T XmlDeserialize<T>(string xml,string root) where T:class
        {
            T result=default(T);
            try
            {
                XmlSerializer xmls = new XmlSerializer(typeof(T),new XmlRootAttribute(root));
                result = (T)xmls.Deserialize(new StringReader(xml));
            }
            catch{ }
            return result;
        }
    }
}
